package cn.jiyun.teacher.service.impl;

import cn.jiyun.teacher.dao.TeacherDao;
import cn.jiyun.teacher.pojo.AdchannelVo;
import cn.jiyun.teacher.pojo.Teacher;
import cn.jiyun.teacher.pojo.TeacherDto;
import cn.jiyun.teacher.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherDao teacherDao;
    @Override
    public Page findPage(TeacherDto teacherDto) {
        Page<Teacher> page = new Page<>(teacherDto.getPage(),teacherDto.getPageSize());
        Page<Teacher> page1 = teacherDao.selectPage(page, null);
        return page1;
    }

    @Override
    public AdchannelVo add(Teacher teacher) {
        teacherDao.insert(teacher);
        AdchannelVo adchannelVo = new AdchannelVo();
        adchannelVo.setCode(2000);
        adchannelVo.setMsg("添加成功");
        return adchannelVo;
    }

    @Override
    public Teacher findById(Integer cid) {
        LambdaQueryWrapper<Teacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Teacher::getCid,cid);
        return teacherDao.selectOne(wrapper);
    }

    @Override
    public AdchannelVo edit(Teacher teacher) {
        teacherDao.updateById(teacher);
        AdchannelVo adchannelVo = new AdchannelVo();
        adchannelVo.setCode(2000);
        adchannelVo.setMsg("修改成功");
        return adchannelVo;
    }
}
